package com.cmc.cloud.cmclink.doc.service.impl.si;

import java.util.Collection;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import com.cmc.cloud.cmclink.doc.constants.errorconstant.BlnoLocalChargeErrorCodeConstants;
import com.cmc.cloud.cmclink.doc.convert.BlnoLocalChargeDetailConvert;
import com.cmc.cloud.cmclink.doc.entity.BlnoLocalChargeDetailDO;
import com.cmc.cloud.cmclink.doc.mapper.BlnoLocalChargeDetailMapper;
import com.cmc.cloud.cmclink.doc.service.si.BlnoLocalChargeDetailService;
import com.cmc.cloud.cmclink.doc.vo.blnochargevo.BlnoLocalChargeDetailCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnochargevo.BlnoLocalChargeDetailUpdateReqVO;
import com.cmes.framework.common.exception.util.ServiceExceptionUtil;

/**
 * Local Charge费用详情 Service 实现类
 *
 * @author 集运管理员
 */
@Service
@Validated
public class BlnoLocalChargeDetailServiceImpl implements BlnoLocalChargeDetailService {

    @Resource
    private BlnoLocalChargeDetailMapper blnoLocalChargeDetailMapper;

    @Override
    public void createBlnoLocalChargeDetail(BlnoLocalChargeDetailCreateReqVO createReqVO) {
        // 插入
        BlnoLocalChargeDetailDO blnoLocalChargeDetail = BlnoLocalChargeDetailConvert.INSTANCE.convert(createReqVO);
        blnoLocalChargeDetailMapper.insert(blnoLocalChargeDetail);
    }

    @Override
    public void updateBlnoLocalChargeDetail(BlnoLocalChargeDetailUpdateReqVO updateReqVO) {
        // 校验存在
        validateBlnoLocalChargeDetailExists(updateReqVO.getId());
        // 更新
        BlnoLocalChargeDetailDO updateObj = BlnoLocalChargeDetailConvert.INSTANCE.convert(updateReqVO);
        blnoLocalChargeDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteBlnoLocalChargeDetail(Long id) {
        // 校验存在
        validateBlnoLocalChargeDetailExists(id);
        // 删除
        blnoLocalChargeDetailMapper.deleteById(id);
    }

    private void validateBlnoLocalChargeDetailExists(Long id) {
        if (blnoLocalChargeDetailMapper.selectById(id) == null) {
            throw ServiceExceptionUtil.exception(BlnoLocalChargeErrorCodeConstants.BLNO_LOCAL_CHARGE_DETAIL_NOT_EXISTS);
        }
    }

    @Override
    public BlnoLocalChargeDetailDO getBlnoLocalChargeDetail(Long id) {
        return blnoLocalChargeDetailMapper.selectById(id);
    }

    @Override
    public List<BlnoLocalChargeDetailDO> getBlnoLocalChargeDetailList(Collection<Long> ids) {
        return blnoLocalChargeDetailMapper.selectBatchIds(ids);
    }
}
